program TestAnim;

uses
  Windows, SysUtils,
  S2DMain, S2DTypes, S2DSWCanvas;

const MAX = 50;

type
  TMiku = record
    X, Y,
    SX, SY: Single;
    Mirror,
    Age,
    Aging: Byte;
  end;

var
  MikuSpr: TBuffer;
  Miku   : array [1..MAX] of TMiku;
  I      : Word;

begin
  LoadBMP(MikuSpr, 'Images\Miku.bmp');
  Randomize;
  for I:= 1 to MAX do
    with Miku[I] do
    begin
      Mirror:= Random(5);
      if Mirror = 0 then
      begin
        X:= -Random(512)-128;
        SX:= -((Random(40)+10)/10);
      end
      else
      begin
        X:= Random(512)+800;
        SX:= (Random(40)+10)/10;
      end;
      Y:= Random(600);
      SY:= (random(10)-10)/10;
      Age:= Random(8);
      Aging:= Random(100);
    end;
  InitWindow(800, 600);
  ShowCursor(FALSE);
  repeat
    ClearBuffer(Screen, 0);
    for I:= 1 to MAX do
      with Miku[I] do
      begin
        Inc(Aging, Round(8*(FrameTime/20)));
        if Aging>=64 then
        begin
          Inc(Age);
          Aging:= 0;
        end;
        if Age>=8 then
          Age:= 0;
        X:= X-Round(SX*(FrameTime/20));
        Y:= Y+Round(SY*(FrameTime/20));
        if (X<-1024) OR (Y<-128) OR (X>800+1024) OR (Y>600+128) then
        begin
          Mirror:= Random(2);
          if Mirror = 0 then
          begin
            X:= -Random(512)-128;
            SX:= -((Random(40)+10)/10);
          end
          else
          begin
            X:= Random(512)+800;
            SX:= (Random(40)+10)/10;
          end;
          Y:= Random(600);
          SY:= (random(10)-10)/10;
          Age:= Random(8);
          Aging:= Random(100);
        end;
        if Mirror = 0 then
          PutBufferMirrorX(Screen, MikuSpr, Round(X), Round(Y), 128*Age, 0, 128, 128, $FF00FF)
        else
          PutBuffer(Screen, MikuSpr, Round(X), Round(Y), 128*Age, 0, 128, 128, $FF00FF);
      end;
    SysText(Screen, 10, 10, 'FPS        : '+IntToStr(S2DInfo.FPS), $FFFFFF);
    SysText(Screen, 10, 20, 'Memory used: '+IntToStr(S2DInfo.TotalAllocMemory)+' bytes', $FFFFFF);
    GetMessages;
  until NOT S2DInfo.Running OR KeyMap[VK_ESCAPE];
  FreeBuffer(MikuSpr);
  CloseWindow;
end.

